name: On Open
on:
  issues:
    types: [opened]

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Actions
        uses: actions/checkout@v4
        with:
          repository: "microsoft/vscode-github-triage-actions"
          ref: stable
          path: ./actions
      - name: Install Actions
        run: npm install --production --prefix ./actions

      - name: Check for Validity
        uses: ./actions/validity-checker
        with:
          token: ${{secrets.VSCODE_ISSUE_TRIAGE_BOT_PAT}}

      - name: Run CopyCat (VSCodeTriageBot/testissues)
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/copycat
        with:
          appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
          token: ${{secrets.VSCODE_ISSUE_TRIAGE_BOT_PAT}}
          owner: VSCodeTriageBot
          repo: testissues

      - name: Run New Release
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/new-release
        with:
          label: new release
          token: ${{secrets.VSCODE_ISSUE_TRIAGE_BOT_PAT}}
          appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
          labelColor: "006b75"
          labelDescription: Issues found in a recent release of VS Code
          oldVersionMessage: "Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is {currentVersion}. Please try upgrading to the latest version and checking whether this issue remains.\n\nHappy Coding!"
          days: 5

      - name: Run Clipboard Labeler
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/regex-labeler
        with:
          appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
          label: "invalid"
          mustNotMatch: "^We have written the needed data into your clipboard because it was too large to send\\. Please paste\\.$"
          comment: "It looks like you're using the VS Code Issue Reporter but did not paste the text generated into the created issue. We've closed this issue, please open a new one containing the text we placed in your clipboard.\n\nHappy Coding!"

      - name: Run Clipboard Labeler (Chinese)
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/regex-labeler
        with:
          appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
          label: "invalid"
          mustNotMatch: "^所需的数据太大，无法直接发送。我们已经将其写入剪贴板，请粘贴。$"
          comment: "看起来您正在使用 VS Code 问题报告程序，但是没有将生成的文本粘贴到创建的问题中。我们将关闭这个问题，请使用剪贴板中的内容创建一个新的问题。\n\n祝您使用愉快！"

      # source of truth in ./english-please.yml
      - name: Run English Please
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/english-please
        with:
          token: ${{secrets.VSCODE_ISSUE_TRIAGE_BOT_PAT}}
          appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
          cognitiveServicesAPIKey: ${{secrets.AZURE_TEXT_TRANSLATOR_KEY}}
          nonEnglishLabel: "*english-please"
          needsMoreInfoLabel: "info-needed"
          translatorRequestedLabelPrefix: "translation-required-"
          translatorRequestedLabelColor: "c29cff"
            # source of truth in ./test-plan-item-validator.yml
      - name: Run Test Plan Item Validator
        if: github.event.issue.user.login != 'ghost'
        uses: ./actions/test-plan-item-validator
        with:
          token: ${{secrets.VSCODE_ISSUE_TRIAGE_BOT_PAT}}
          refLabel: on-testplan
          label: testplan-item
          invalidLabel: invalid-testplan-item
          comment: Invalid test plan item. See errors below and the [test plan item spec](https://github.com/microsoft/vscode/wiki/Writing-Test-Plan-Items) for more information. This comment will go away when the issues are resolved.

